package wei.qiang.ye.druiddatasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import javax.sql.DataSource;

@SpringBootApplication
public class DruidDatasourceApplication implements CommandLineRunner {
    private Logger logger = LoggerFactory.getLogger(DruidDatasourceApplication.class);


    public static void main(String[] args) {
		SpringApplication.run(DruidDatasourceApplication.class, args);
	}

	//单数据源
//    @Autowired
//    private DataSource dataSource;
//    @Override
//    public void run(String... args) throws Exception {
//        logger.info("[run][获得数据源：{}]", dataSource.getClass());
//    }

    //多数据源
    @Resource(name = "liughDataSource")
    private DataSource liughDataSource;

    @Resource(name = "usersDataSource")
    private DataSource usersDataSource;

    @Override
    public void run(String... args) {
        // liugh 数据源
        logger.info("[run][获得数据源：{}]", liughDataSource.getClass());

        // users 数据源
        logger.info("[run][获得数据源：{}]", usersDataSource.getClass());
    }
}
